home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / keyb / togkey.zip / TOGKEY.ASM < prev    next >
Assembly Source File  |  1988-01-08  |  6KB  |  294 lines

  1. page 55,132
  2. title TOGKEY -- Toggles the Insert, Caps, Num, Scroll, or Suspend (Hold) key.
  3.  
  4. ;
  5. FALSE    EQU    0
  6. TRUE    EQU    NOT FALSE
  7. vn    equ    "1"    ;version number
  8. rn    equ    "0"    ;revision number
  9. ;
  10. data    segment at 40h
  11. ;
  12. foo        db    16h dup(?)
  13. ;
  14. kb_flag        dw    ?    ;Keyboard Status
  15. ;
  16. INS_STATE    EQU     8000H
  17. CAPS_STATE    EQU     4000H
  18. NUM_STATE    EQU     2000H
  19. SCROLL_STATE    EQU     1000H
  20. ALT_SHIFT    EQU     0800H
  21. CTL_SHIFT    EQU     0400H
  22. LEFT_SHIFT    EQU     0200H
  23. RIGHT_SHIFT    EQU     0100H
  24. ;
  25. kb_flage_1     db    ?        ;Second byte of Keyboard Status
  26. ;
  27. INS_SHIFT    EQU    80H
  28. CAPS_SHIFT    EQU    40H
  29. NUM_SHIFT    EQU    20H
  30. SCROLL_SHIFT    EQU    10H
  31. HOLD_STATE    EQU    08H
  32.     ;
  33. data ends
  34.  
  35. ;
  36. ;       MISCELLANEOUS EQUATES
  37. ;
  38. CR      EQU     0dh
  39. LF      EQU     0ah
  40. eom    equ    0    ;End of string char (did you think I was going to
  41.             ;use '$' ?!!!)
  42. DosCall EQU     21h    ;INTERUPT NUMBER FOR DOS CALL
  43. ;
  44. prognam    segment    public
  45.     ;
  46. ;
  47.     assume    cs:prognam,ds:prognam,ss:prognam
  48.     org    80h
  49. psiz    db    ?
  50. pstng    db    ?
  51.     org     100h
  52.             ;
  53. start:    jmp    intial
  54.     db    cr,lf,"TOGKEY ver:",vn,".",rn
  55.     db    cr,lf,"Copyright 1988 by Timothy M. Pozar"
  56.     db    cr,lf,"Please don't rip me off!!",cr,lf,1ah    ;ends with a ^Z
  57.     db    57h,08h,20h,32h,20h    ;ser
  58.     ;
  59. intial:    mov    ax,cs
  60.     mov    ds,ax
  61.     mov    ss,ax
  62.     mov     sp,offset stack    
  63.     ;
  64. begin:                ;beginning of programme
  65.     mov    al,psiz        ;how many char are on the command line
  66.     mov    switch_num,al
  67.     cmp    al,0
  68.     jz    help        ;if there is none, display help msg
  69.     cmp    al,1
  70.     jnz    nohelp        ;if there is just one, display help msg
  71.                 ;else skip over and start parsing
  72. help:
  73.     mov    dx,offset signon_msg
  74.     call     pstring
  75.     jmp    done
  76. nohelp:
  77.     sub    cx,cx    
  78.     mov    cl,switch_num
  79.     mov    si,offset pstng    ;start of command string
  80.     cld
  81.     ;
  82. lp1:    
  83.     lodsb
  84.     cmp    al,switch_char1
  85.     jz    tswtch
  86.     cmp    al,switch_char2
  87.     jz    tswtch
  88.     jmp    lpend
  89. tswtch:    push    ax
  90.     mov    ax,TRUE
  91.     mov    switch_rcv,ax
  92.     pop    ax
  93.     dec    cx        ;test for what switch char is there
  94.     lodsb
  95. ;
  96. tog_ins1:
  97.     cmp    al,"i"
  98.     jz    tog_ins2
  99.     cmp    al,"I"
  100.     jnz    tog_cap1
  101. tog_ins2:            ;set insert flag to true
  102.     mov    ax,TRUE
  103.     mov    insert_flg,ax
  104.     jmp    lpend
  105. ;
  106. tog_cap1:
  107.     cmp    al,"c"        ;set caps flag to true
  108.     jz    tog_cap2
  109.     cmp    al,"C"
  110.     jnz    tog_num1
  111. tog_cap2:
  112.     mov    ax,TRUE
  113.     mov    caps_flg,ax
  114.     jmp    lpend
  115. ;
  116. tog_num1:
  117.     cmp    al,"n"        ;set numlock flag to true
  118.     jz    tog_num2
  119.     cmp    al,"N"
  120.     jnz    tog_scroll1
  121. tog_num2:
  122.     mov    ax,TRUE
  123.     mov    num_flg,ax
  124.     jmp    lpend
  125. ;
  126. tog_scroll1:
  127.     cmp    al,"s"        ;set scroll flag to true
  128.     jz    tog_scroll2
  129.     cmp    al,"S"
  130.     jnz    defalt
  131. tog_scroll2:
  132.     mov    ax,TRUE
  133.     mov    scroll_flg,ax
  134.     jmp    lpend
  135.  
  136. defalt:
  137.             ;Did not reconize this char as a valid command.
  138.     push    ax
  139.     mov    dx,offset duh_msg
  140.     call    pstring
  141.     pop    ax
  142.     call    pchar
  143.     mov     al,'.'
  144.     call    pchar
  145.     jmp    done
  146.  
  147. lpend:    loop    lp1
  148.     ;
  149. lpfin:
  150.     mov    ax,switch_rcv        ;did we get a valid switch char some
  151.     cmp    ax,TRUE            ;where in there?
  152.     jz    main
  153.     mov    dx,offset no_swtch_msg    ;if not, bomb out
  154.     call    pstring
  155.     jmp    done
  156. ;
  157. ;       M A I N
  158. ;
  159. main:
  160.     ;
  161. flip_cap:
  162.     mov    ax,caps_flg
  163.     cmp    ax,true
  164.     jnz    flip_ins
  165.     mov    dx,offset capsmsg
  166.     call    pstring
  167.     mov    cx,CAPS_STATE
  168.     call    modkeyb
  169.     ;
  170. flip_ins:
  171.     mov    ax,insert_flg
  172.     cmp    ax,true
  173.     jnz    flip_num
  174.     mov    dx,offset insmsg
  175.     call    pstring
  176.     mov    cx,INS_STATE
  177.     call    modkeyb
  178.     ;
  179. flip_num:
  180.     mov    ax,num_flg
  181.     cmp    ax,true
  182.     jnz    flip_scroll
  183.     mov    dx,offset nummsg
  184.     call    pstring
  185.     mov    cx,NUM_STATE
  186.     call    modkeyb
  187.     ;
  188. flip_scroll:
  189.     mov    ax,scroll_flg
  190.     cmp    ax,true
  191.     jnz    done
  192.     mov    dx,offset scrollmsg
  193.     call    pstring
  194.     mov    cx,SCROLL_STATE
  195.     call    modkeyb
  196.     ;
  197.  
  198. done:
  199.     mov    dx,offset newline
  200.     call     pstring
  201.     mov    ah,4ch
  202.     int    DosCall        ; That's all Folks !
  203.     ;
  204.  
  205. modkeyb    proc    near
  206.     push    ds
  207.     mov    ax,data
  208.     mov    ds,ax
  209.     mov    bx,offset kb_flag
  210.     xor    [bx],cx
  211.     pop    ds
  212.     ret
  213. modkeyb endp
  214.  
  215. pstring    proc    near
  216.     ;SAMPLE CALL TO PSTRING
  217.     ;mov    dx,offset anounc ;point to address of message "anounc"
  218.     ;call     pstring        ;display anounc
  219.     ;
  220.     mov    bx,dx
  221. pmore:    mov    al,[bx]
  222.     cmp    al,eom
  223.     jz    pfin
  224.     call    pchar
  225.     inc    bx
  226.     jmp    pmore
  227. pfin:    ret
  228.     ;
  229. pstring    endp
  230. ;
  231. pchar    proc    near
  232.     ;sends one char to the console
  233.     mov    ah,2
  234.     mov    dl,al
  235.     int    DosCall
  236.     ret
  237.     ;
  238. pchar    endp
  239.  
  240.  
  241. ;ZEE DATA AREA --
  242. ;
  243. ;Messages
  244. ;
  245. no_swtch_msg db    cr,lf,"  Did not find the current switch character on the command"
  246.     db    cr,lf,"  line.  Please use either '/' or '-'."
  247.     db      eom
  248. duh_msg db    cr,lf,"  Did not reconize the command line switch character "
  249.     db      eom
  250. newline db    cr,lf,eom
  251. capsmsg    db    cr,lf,"  Changeing state of the CapsLock key.",eom
  252. insmsg    db    cr,lf,"  Changeing state of the Insert key.",eom
  253. nummsg    db    cr,lf,"  Changeing state of the NumLock key.",eom
  254. scrollmsg db    cr,lf,"  Changeing state of the ScrollLock key.",eom
  255.     ;
  256. signon_msg db    cr,lf,"TOGKEY ver:",vn,".",rn," 8.Jan.88"
  257.     db    cr,lf,"  Copyright (c)1988 T. M. Pozar"
  258.     db    cr,lf,"  Voice (415) 788-2022 / Data  (415) 391-2657"
  259.     db    cr,lf,"  Use limited to private (non-commercial) only.  Commercial use, by the "
  260.     db      cr,lf,"  written permission of the author only."
  261.     db    cr,lf," "
  262.     db    cr,lf,"  TOGKEY will toggle the state of a paticular key, such as the CapsLock, or"
  263.     db    cr,lf,"  Insert keys.  In order to toggle those keys the associated command line"
  264.     db      cr,lf,"  switch must be specified.  For example:"
  265.     db    cr,lf,"     A>togkey -N -C <return>"
  266.     db    cr,lf," "
  267.     db    cr,lf,"  In this example we have told the programme to toggle the state of the"
  268.     db    cr,lf,"  NumLock and CapsLock keys.  (See below for the switch settings.)  This"
  269.     db    cr,lf,"  will not change the lights on the keyboard, it will only change the state"
  270.     db    cr,lf,"  table in memory."
  271.     db    cr,lf," "
  272.     db    cr,lf,"Switch Settings...  (Should be preceded by '-' or '/')"
  273.     db    cr,lf,"  C = CapsShift (or CapsLock)"
  274.     db    cr,lf,"  I = Insert"
  275.     db    cr,lf,"  N = NumShift (or NumLock)"
  276.     db    cr,lf,"  S = ScrollShift"
  277.     db    eom
  278.     ;
  279. ;
  280. ;
  281. switch_num    db    0
  282. switch_char1    db    "-"
  283. switch_char2    db    "/"
  284. switch_rcv    dw    FALSE        ;TRUE = got a valid switch char on command line
  285. caps_flg    dw    FALSE        ;TRUE = toggle caps lock state
  286. insert_flg    dw    FALSE        ;TRUE = toggle insert state
  287. num_flg        dw    FALSE        ;TRUE = toggle num lock state
  288. scroll_flg    dw    FALSE        ;TRUE = toggle scroll lock state
  289.     ;
  290.          db    10 dup ('stack   ')    ;room for stack
  291. stack    label     byte        ;top of stack
  292. prognam    ends
  293.     end start
  294.